package com.lagou.zk;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayHandler;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import org.junit.Test;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

/**
 * @Author Cao Dun
 * @Date 2021/3/23 21:03
 * @Version 1.0
 * @Description
 */
public class testDButils {

    @Test
    public void test() throws SQLException {
        //1.创建QueryRunner
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        //2.编写SQL
        String sql = "select * from emp";

        //3.执行查询
        List<Object[]> queryList = qr.query(sql, new ArrayListHandler());

        //4.获取数据
        for (Object[] objects : queryList) {
            System.out.println(Arrays.toString(objects));
        }
    }
}
